(function (vc, vm) {
    vc.extends({
        data: {
            editShopVipUserInfo: {
                vipId: '',
                vipName: '',
                vipTel: '',
                sex: '',
                vipLevel: '',
                birthday: '',
                startTime: '',
                endTime: '',
                shopId: vc.getCurrentCommunity().shopId,
                vipLevels: [],
                sexs: []
            }
        },
        _initMethod: function () {
            vc.initDate('editBirthday', function (_value) {
                $that.editShopVipUserInfo.birthday = _value;
            });
            vc.initDate('editStartTime', function (_value) {
                $that.editShopVipUserInfo.startTime = _value;
            });
            vc.initDate('editEndTime', function (_value) {
                $that.editShopVipUserInfo.endTime = _value;
            });
        },
        _initEvent: function () {
            vc.on('editShopVipUser', 'openEditShopVipUserModal', function (_params) {
                $that.refreshEditShopVipUserInfo();
                $('#editShopVipUserModel').modal('show');
                vc.getDict('s_shop_vip_user', "sex", function (_data) {
                    $that.editShopVipUserInfo.sexs = _data;
                });
                vc.copyObject(_params, $that.editShopVipUserInfo);
                $that.editShopVipUserInfo.birthday = vc.dateFormat($that.editShopVipUserInfo.birthday);
                $that.editShopVipUserInfo.startTime = vc.dateFormat($that.editShopVipUserInfo.startTime);
                $that.editShopVipUserInfo.endTime = vc.dateFormat($that.editShopVipUserInfo.endTime);
                $that._listEditShopVipLevels();
                $that.editShopVipUserInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editShopVipUserValidate: function () {
                return vc.validate.validate({
                    editShopVipUserInfo: $that.editShopVipUserInfo
                }, {
                    'editShopVipUserInfo.vipName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "会员名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "会员名称太长"
                        },
                    ],
                    'editShopVipUserInfo.vipTel': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "会员电话不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "会员电话格式错误"
                        },
                    ],
                    'editShopVipUserInfo.sex': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "性别不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "性别错误"
                        },
                    ],
                    'editShopVipUserInfo.vipLevel': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "会员等级不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "会员等级错误"
                        },
                    ],
                    'editShopVipUserInfo.birthday': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "会员生日不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "会员生日格式错误"
                        },
                    ],
                    'editShopVipUserInfo.startTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "开始时间格式错误"
                        },
                    ],
                    'editShopVipUserInfo.endTime': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "结束时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "结束时间格式错误"
                        },
                    ],
                    'editShopVipUserInfo.vipId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "主键不能为空"
                        }
                    ]
                });
            },
            editShopVipUser: function () {
                if (!$that.editShopVipUserValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/shopVipUser/updateShopVipUser',
                    JSON.stringify($that.editShopVipUserInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopVipUserModel').modal('hide');
                            vc.emit('shopVipUserManage', 'listShopVipUser', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditShopVipUserInfo: function () {
                $that.editShopVipUserInfo = {
                    vipId: '',
                    vipName: '',
                    vipTel: '',
                    sex: '',
                    vipLevel: '',
                    birthday: '',
                    startTime: '',
                    endTime: '',
                    shopId: vc.getCurrentCommunity().shopId,
                    vipLevels: [],
                    sexs: []
                }
            },
            _listEditShopVipLevels: function (_page, _rows) {
                var param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/shopVipUser.queryShopVipLevel',
                    param,
                    function (json, res) {
                        var _shopVipLevelManageInfo = JSON.parse(json);
                        $that.editShopVipUserInfo.vipLevels = _shopVipLevelManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            }
        }
    });
})(window.vc, window.vc.component);
